import $ from 'jquery'
import '@/assets/zTreeStyle/zTreeStyle.css'
import '@ztree/ztree_v3/js/jquery.ztree.core'
import '@ztree/ztree_v3/js/jquery.ztree.excheck'
import '@ztree/ztree_v3/js/jquery.ztree.exhide'
import jscookie from 'js-cookie'
const ztreeOption = ({
    onCheck,
    url,
    dataFilter,
    chkStyle,
    async = false,
    autoParam = ["id"],
    onExpand = () => { },
    beforeAsync = () => { return true },
}) => {
    const ztreeSetting = {
        async: {
            enable: async,
            type: 'get',
            autoParam,
            url,
            headers: {
                redirectUrl: window.location.href,
                'micro-token': jscookie.get('micro-token')
            },
            dataFilter,
        },
        check: {
            enable: true,
            chkStyle,
            radioType: 'all',
            chkboxType: {
                "Y": "", // 父节点被选中时，子节点的勾选状态
                "N": "" // 子节点被选中时，父节点的勾选状态
            }
        },
        data: {
            key: {
                title: 'name'
            },
            simpleData: {
                enable: true,
                idKey: 'id',
                pIdKey: 'parentId',
                rootPId: '-1'
            }
        },
        callback: {
            onCheck,
            onExpand,
            beforeAsync
        }
    }
    return ztreeSetting
}

export default ztreeOption